package org.makabaka.wfwwb.utils;

import cn.hutool.core.util.StrUtil;
import cn.hutool.jwt.JWTUtil;
import org.makabaka.wfwwb.pojo.User;

import java.util.HashMap;
import java.util.Map;


public class UserUtil {
    private static final String SECRET_KEY = "mkbkforever"; // 签名密钥


    public static String getToken(User user) {
        Map<String, Object> map = new HashMap<String, Object>() {
            private static final long serialVersionUID = 1L;
            {
                put("username", user.getUsername());
                put("expire_time", System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 15);
            }
        };

        String token = JWTUtil.createToken(map, SECRET_KEY.getBytes());
        return token;


    }

    public static boolean verifyToken(String token) {
        if (StrUtil.isBlank(token)) {
            return false;
        }
        return JWTUtil.verify(token, SECRET_KEY.getBytes());
    }



}
